<template>
  <router-view/>
</template>

<style>

</style>
<script setup>

// 设置前置路由守卫
import router from "@/router";
import {showNotify} from "vant";

router.beforeEach((to, from, next)=>{
  //路由中导入-开始
  if (to.fullPath !== '/login') {
    if (getUser() === null) {
      showNotify({ type: 'warning', message: '请先登录一下吧' });
      router.replace('/login')
      return;
    }
  }
  next()
})

</script>
<script>
import {ref} from "vue";
import request from "@/assets/js/mobileRequest";

export const currentUser = ref(null)
export const getUser = () => {
  request({
    method: "get",
    url: BASE_URL+"/v1/user/selectCurrent"
  }).then(res => {
    if (res.data.code === 2000) {
      currentUser.value = res.data.data
    }
  })
  return currentUser.value;
}
export default {
  data() {
    return {
      loginUser: ref()
    }
  }
}

</script>
